import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class BSQX01 {
    /**
     * 当月份为素数时, 当月每天能赚1元,否则每天能赚2元
     * 现给你一段时间区间,请你帮他计算总收益右多少
     * 输入包含多组数据 ,每组数据包含两个日期from 和 to(2000 1 1 2000 1 31)
     * 日期之间用三个正整数表示,用空格隔开:year month day
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextInt()) {
            int fromYear = sc.nextInt();
            int fromMonth = sc.nextInt();
            int fromDay = sc.nextInt();
            int toYear = sc.nextInt();
            int toMonth = sc.nextInt();
            int toDay = sc.nextInt();

            Set<Integer> set = new HashSet<>();//添加素数方便查找
            set.add(2);set.add(3);set.add(5);
            set.add(7);set.add(11);
            int money=0;
            int day=0;
            if(fromYear==toYear) {
                if(fromMonth == toMonth) {
                    money = sameMonth(fromDay, fromMonth, fromYear, toDay, toMonth, toYear, set);
                }else {
                    money = sameYear(fromDay, fromMonth, fromYear, toDay, toMonth, toYear, set);
                }
            }else {//不同年
                money += sameYear(fromDay, fromMonth, fromYear, 31, 12, fromYear, set);//第一年
                money += sameYear(1, 1, toYear, toDay, toMonth, toYear, set);//最后一年
                int temp = fromYear+1;
                while( temp<toYear){
                    money += sameYear(1, 1, temp, 31, 12, temp, set);
                    temp++;
                }

            }
            System.out.println(money);

        }
    }
    //是否是闰年
    public static boolean isLeapYear(int year) {
        return (year%4==0&&year%100!=0)||year%400==0;
    }
    //计算某个月多少天
    public static int manyDay(int year,int month) {
        switch(month) {
            case 1:case 3:case 5 :
            case 7:case 8: case 10:case 12:return 31;
            case 4:case 6:case 9:case 11:return 30;
            default:
                if(isLeapYear(year)==true) {
                    return 29;
                }
                else {
                    return 28;
                }
        }
    }
    //同年不同月
    public static int sameYear(int fromDay,int fromMonth,int fromYear,int toDay,int toMonth,int toYear,Set<Integer>set) {
        int money = 0;
        int day = 0;
        day = manyDay(fromYear, fromMonth)-fromDay+1;//初始月的天数,包括初始日期
        if(set.contains(fromMonth)) {//是否是素月
            money += day*1;
        }else {
            money += day*2;
        }
        day = toDay;//结束月的天数
        if(set.contains(toMonth)) {
            money += day*1;
        }else {
            money += day*2;
        }

        //中间月
        for(int i = fromMonth+1;i<toMonth;i++) {
            day=manyDay(fromYear, i);
            if(set.contains(i)) {
                money += day*1;
            }else {
                money += day*2;
            }
        }
        return money;
    }
    //同年同月
    public static int sameMonth(int fromDay,int fromMonth,int fromYear,int toDay,int toMonth,int toYear,Set<Integer>set) {
        int money = 0;
        int day = 0;
        day = toDay-fromDay+1;//初始月的天数,包括初始日期
        if(set.contains(fromMonth)) {//是否是素月
            money += day*1;
        }else {
            money += day*2;
        }
        return money;
    }

}
